using Core.SimpleTemp.Common;
using Core.SimpleTemp.Common.PagingQuery;
using Core.SimpleTemp.Entitys;
using Core.SimpleTemp.Repositories;
using Core.SimpleTemp.Repositories.Sys;
using Core.Toolkit.Common;
using Core.Toolkit.Core;
using Core.Toolkit.Core.Api;
using Core.Toolkit.Core.Application;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Core.SimpleTemp.Application
{
    [AutoDi()]
    public class PX_CertificateService : BaseAppService<PX_CertificateDto, PX_Certificate , PX_CertificateRepository>
        {
        readonly ExcelHelp _excelHelp;
        public PX_CertificateService (PX_CertificateRepository repository,ExcelHelp excelHelp) : base(repository){
        _excelHelp = excelHelp;
        }



        private LoadPageOffsetModelAuto<PX_Certificate, PX_CertificateDto>
            GetLoadPageOffsetMode(PagingModel<PX_CertificateDto>
                pagingQueryModel)
                {
                var loadPageOffsetModel = this.GetLoadPageOffsetModelAuto(pagingQueryModel);
                var baseQuery = _repository.QueryBase().AsNoTracking();
                loadPageOffsetModel.QueryWhere = this.CreateQRList()

         .Add("PersonID","=") //
         .Add("PersonnelName","=") //
         .Add("sex","=") //
         .Add("birthDate","=") //
         .Add("LicenseCoding","=") //
         .Add("Licensingauthority","=") //
         .Add("Certificatetype","=") //
         .Add("Nameofcertificate","=") //
         .Add("Issuancetime","=") //
         .Add("Termofvalidity","=") //
         .Add("describe","=") //
         .Add("CreateFactory","=") //
         .Add("CreateDept","=") //
         .Add("UpdateDept","=") ;//


                loadPageOffsetModel.BasqQuery = baseQuery;
                loadPageOffsetModel.Order = orderModel => orderModel.CreateTime;
                loadPageOffsetModel.Selector = model => new  PX_Certificate() {
                Id = model.Id,
PersonID= model.PersonID,//
PersonnelName= model.PersonnelName,//
sex= model.sex,//
birthDate= model.birthDate,//
LicenseCoding= model.LicenseCoding,//
Licensingauthority= model.Licensingauthority,//
Certificatetype= model.Certificatetype,//
Nameofcertificate= model.Nameofcertificate,//
Issuancetime= model.Issuancetime,//
Termofvalidity= model.Termofvalidity,//
describe= model.describe,//
CreateFactory= model.CreateFactory,//
CreateDept= model.CreateDept,//
UpdateDept= model.UpdateDept,//
                };
                return loadPageOffsetModel;
                }


                public async Task <IPageModel<PX_CertificateDto>> GetList(PagingModel<PX_CertificateDto>
                    pagingQueryModel)
                    {
                    var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                    return await base.LoadPageOffsetAsync(loadPageOffsetModel);
                    }


                    public async Task<string>
                        Export(PagingModel<PX_CertificateDto>
                            pagingQueryModel)
                            {
                            var loadPageOffsetModel = GetLoadPageOffsetMode(pagingQueryModel);
                            var DataList = await this.ExportDataAsync(loadPageOffsetModel);
                            var excelData = DataList.Select(model => new
                            {
model.PersonID,
PersonID_title ="",
model.PersonnelName,
PersonnelName_title ="",
model.sex,
sex_title ="",
model.birthDate,
birthDate_title ="",
model.LicenseCoding,
LicenseCoding_title ="",
model.Licensingauthority,
Licensingauthority_title ="",
model.Certificatetype,
Certificatetype_title ="",
model.Nameofcertificate,
Nameofcertificate_title ="",
model.Issuancetime,
Issuancetime_title ="",
model.Termofvalidity,
Termofvalidity_title ="",
model.describe,
describe_title ="",
model.CreateFactory,
CreateFactory_title ="",
model.CreateDept,
CreateDept_title ="",
model.UpdateDept,
UpdateDept_title ="",
                            }).ToList();




                            return _excelHelp.Create(excelData);
                            }

                            }

                            }
